from db.db_base import DBBase, commit, get_one_value, get_one_dict, get_all_dict


__all__ = [
    "DBCustomer"
]


class DBCustomer(DBBase):

    @commit
    def add_info(self, cust_id: str, cust_name: str, cust_tel: str, cust_company: str, cust_icon: str):
        # 加入新的信息
        return """
        INSERT INTO `Customers` 
        (`cust_id`, `cust_name`, `cust_tel`, `cust_company`, `cust_icon`) 
        VALUES (?, ?, ?, ?, ?);
        """

    @commit
    def delete_info(self, cust_id: str):
        # 删除信息
        return """
        DELETE FROM `Customers`
        WHERE `cust_id` = ?;
        """

    @commit
    def update_icon(self, cust_icon: str, cust_id: str):
        # 更新头像
        return """
        UPDATE `Customers`
        SET `cust_icon` = ?
        WHERE `cust_id` = ?;
        """

    @commit
    def update_personal_info(self, cust_name: str, cust_tel: str, cust_company: str, cust_id: str):
        # 更新个人信息
        return """
        UPDATE `Customers`
        SET `cust_name` = ?, `cust_tel` = ?, `cust_company` = ?
        WHERE `cust_id` = ?;
        """

    @get_one_value
    def get_name_by_id(self, cust_id: str):
        # 根据id获取姓名
        return """
        SELECT `cust_name`
        FROM `Customers`
        WHERE `cust_id` = ?;
        """

    @get_one_value
    def get_id_by_name(self, cust_name: str):
        # 根据姓名获取id
        return """
        SELECT `cust_id`
        FROM `Customers`
        WHERE `cust_name` = ?;
        """

    @get_one_dict("Customers")
    def get_info(self, cust_id: str):
        # 获取信息
        return """
        SELECT *
        FROM `Customers`
        WHERE `cust_id` = ?;
        """

    @get_all_dict("Customers")
    def get_all_info(self):
        return None